
  -Outbreak 2 tutorial on angles


   Programmers are probably wondering how I got so many angles without predefining the angles
which takes a huge amount of programming. The secret is trigonometry, the ratio of the sides of
a triangle with a hyponenuse of one. The trig functions will be able to return the length of the
sides for an angle that you specify, the angle of the ball. A unit circle is the easiest way to 
explain the trig functions:
(this is in normal coordinate planes, not cartesian which Qbasic uses. To convert, mirror the
angles over the x axis.)

x = How much to move the ball along the X axis
y = How much to move the ball along the Y axis
a = reflection angle fromt the paddle, in this 
    case, about 60 degrees

               90 degrees
	        ________                   
	       /   y|   \              
	      / axis|    \
	     /      |   /|\
	    /       |  / | \
	   |        | /  |y |				
      180  |________|/a__|__|  0 degrees                
    degrees|x axis  |  x    | 360 degrees
	   |        |       |            opposite 
	    \       |      /     Sine = ----------
	     \      |     /             Hypotonuse
	      \     |    /               adjacent     b = 180 - (a + 90) <--- This dosen't matter,  
	       \____|___/      CoSine = ----------   /|                       just for explanation
                                        Hypotonuse  / |        
               270 degrees                         /  |
                              x = SIN(a)          /   |y
                              y = COS(a)         /    |
    __                                          /    _|       __
 __|  |________________________________________/a___|_|______|  |__
|  |  |                                           x          |  |  |
|  |  |                                                      |  |  |
|  |  |							     |  |  |
|__|  |______________________________________________________|  |__|
   |__|							     |__|

      Note that 60 degrees in Qbasic is down and to the right. The same angle
in cartesian coordinates is 300 degrees

      Now that is explained:
      x = .5
      y = .866025

   Every loop I add x to the X ball coordinate and y to the Y ball coordinate.
Now if you pixel test on all sides of the ball, you can make it bounce,
by inverting the x add or the y add:
                            1
	   	 POINT(Xball + 1, Yball - 1
	                  	 _
	    2            	/ \                  3
POINT(Xball - 1, Yball + 2)    |   |    POINT(Xball + 5, Yball + 2
	               	        \_/
                               4
		 POINT (Xball + 1, Yball + 5)

	If 1 or 4 is true then multiply the y addition amount by -1, to invert it, the
same goes for x. This way you don't have to calculate super slow trig functions 
every loop. Another advantage to this is the ball always goes the same speed, I've 
seen games where they get the angles by saying the Y change is always 1, and the X 
change is the angle, but this causes the ball to go much faster at low angles, making the
game much harder to play.

	So in the game, my code looks something like this:

DO
 program code
 ...
 Xincrease = SIN(angle)
 Yincrease = COS(angle)
 IF POINT(Xball + 2, Yball - 1) <> 0 then Yincrease = Yincrease * -1'Yball - 1 if for a buffered pixel
 IF POINT(Xball + 2, Yball + 5) <> 0 then Yincrease = Yincrease * -1'ditto
 IF POINT(Xball + 5, Yball + 2) <> 0 then Xincrease = Xincrease * -1'ditto
 IF POINT(Xball - 1, Yball + 2) <> 0 then Xincrease = Xincrease * -1'ditto
 oldXball = Xball
 oldYball = Yball 
 Xball = Xball + Xincrease
 Yball = Yball + Yincrease
 PUT (oldXball, oldYball), ball 'Mask old ball
 PUT (Xball, Yball), ball       'New ball position
 program code
 ....
LOOP
******All code is untested! might have glitches...*******




